<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
        <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
        <title>随手快递</title>
        <link rel="stylesheet" type="text/css" href="../../AUI/css/aui.css" />
        <link rel="stylesheet" type="text/css" href="../../font-awesome/css/font-awesome.min.css" />
        <style type="text/css">
            .la {
                width: 100%;
                padding: 10px 20px;
                text-align: center;
            }
            input[type="text"], input[type="password"]{
                width:80%;
                height: 30px;
                border-bottom: 1px solid #bfbfbf;
                color: #626262;
                font-size: 15px;
                padding-left:10px ;
                margin: auto;
            }
        </style>
    </head>
    <body>
        <header class="aui-bar aui-bar-nav" id="aui-header">
            <a class="aui-btn aui-pull-left" tapmode onclick="history.back();">
                <span class="aui-iconfont aui-icon-left"></span>
            </a>
            <div class="aui-title">账号密码登录</div>
            <div class="aui-btn aui-pull-right"></div>
        </header>
        <div class="aui-content" style="margin-top: 60px">
            <div class="la">
                <input type="text" placeholder="请输入帐号" id="username">
            </div>
            <div class="la">
                <input type="password" placeholder="请输入密码" id="password">
            </div>
            <div class="aui-pull-right" style="margin:10px 10% 0 0px;"><a href="forgetPwd.html" style="color: #b2bf89">忘记密码</a></div>
                
        </div>
        <div style="clear: both;"></div>
        <div  style="text-align: center;margin-top: 20px">
            <div class="aui-btn aui-btn-success" style="width: 70%;height: 35px;line-height: 35px;background: rgb(40, 174, 161)" id="login">登录</div></div>
        </div>


        <script type="text/javascript" src="../../myJs/jquery-1.12.1.min.js" ></script>
        <script src="../../myJs/jquery.cookie.js"></script>
        <script type="text/javascript" src="../../myJs/index.js" ></script>
        <script src="../../myJs/jmessage-sdk-web.2.3.0.min.js"></script>
        <script src="../../myJs/md5.js"></script>
        <script src="../../myJs/JmessageInit.js"></script>
        <script src="../../AUI/script/aui-toast.js"></script>
  
        <script>
            var JIM = new JMessage();
            var toast = new auiToast();
            var loginUsername = localStorage.loginUsername;
            var loginPassword = localStorage.loginPassword;


            $(document).ready(function() {
                if(typeof(loginUsername)!="undefined"&&typeof(loginPassword)!="undefined")
                {
                    $("#username").val(loginUsername);
                    $("#password").val(loginPassword);
                }
                init();
            })

            function init()
            {
                var appkey = "a063bae8671dc9c2c3061d63";
                var random_str = "022cd9fd995849b58b3ef0e943421ed9";
                var time = new Date().getTime();
                var signature = hex_md5("appkey="+appkey+"&timestamp=" +
                        time + "&random_str="+random_str+"&key=e5d5124b67e1c33c0387a745");

                JIM.init({
                    "appkey": appkey,
                    "random_str": random_str,
                    "signature": signature,
                    "timestamp": time,
                }).onSuccess(function(data) {
                    console.log('success:' + JSON.stringify(data));
                }).onFail(function(data){console.log("fail")})
            }

            $("#login").click(function() {
            var username = $("#username").val();
            var password = $("#password").val();
           if(username==""){
                alertmd("请输入帐号");
                return false;
            }
            if (!username.match(/^1[34578]\d{9}$/)) {
                alertmd("手机号码格式不正确");
                $("#username").val("");
                return false;
            }
            if(password==""){
                alertmd("请输入密码");
                return false;
            }
        
          $.ajax({
             type: "post",
             url: '/randomdelivery/userLoginController/login',
             data: {
             username:username,
             password:password
             },
             datatype: "json",
             success: function (data) {
             //alert(JSON.stringify(data));
             //alert(data.msg.userId);
             if(data.code!=200){
            	 $("#username").val("");
                  $("#password").val("");
            	 alertmd("用户名或密码错误");
             }else{
                 sessionStorage.setItem("userId", data.msg.userId);
                 sessionStorage.setItem("userState", data.msg.userState);
                 localStorage.loginUsername=$("#username").val();
                 localStorage.loginPassword=$("#password").val();
             location.href='../helpBuy/index.html';
             }
             }
             });
            })


      /*       $("#login").click(function() {
                JIM.login(
                        {
                            "username":$("#username").val(),
                            "password":$("#password").val()
                        }
                ).onSuccess(function(data){
                            //alert("登录成功");
                	  var username = $("#username").val();
                      var password = $("#password").val();
                     if(username==""){
                          alertmd("请输入帐号");
                          return false;
                      }
                      if (!username.match(/^1[34578]\d{9}$/)) {
                          alertmd("手机号码格式不正确");
                          $("#username").val("");
                          return false;
                      }
                      if(password==""){
                          alertmd("请输入密码");
                          return false;
                      }
                    
                    $.ajax({
                       type: "post",
                       url: '/randomdelivery/userLoginController/login',
                       data: {
                       username:username,
                       password:password
                       },
                       datatype: "json",
                       success: function (data) {
                       //alert(JSON.stringify(data));
                       //alert(data.msg.userId);
                           sessionStorage.setItem("userId", data.msg.userId);
                           sessionStorage.setItem("userState", data.msg.userState);
                           localStorage.loginUsername=$("#username").val();
                           localStorage.loginPassword=$("#password").val();
                       location.href='../helpBuy/index.html';
                       }

                       });
                        })
                        .onFail(function(data){

                            toast.success({

                                        title:"登录失败",
                                        duration:2000
                                    }

                            )
                        })
            })

            function forgetPassowrd()
            {
                alert("忘了那就去想起来呗");
            } */

        </script>
    </body>
</html>